<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../connection/connection.php';
include '../value/value_kr.php';

	$monitorid = $_REQUEST['monitorid'];
	$idcamera = $_REQUEST['idcamera'];
	$idposcamera = $_REQUEST['idposcamera'];
	$winH = $_REQUEST['winH'];

	$list=$_SESSION['sort'];
	
	if(!isset($_REQUEST['pages'])){
		$list["fa.camera_ID"]="DESC";
		$list["fa.pos"]="DESC";
		$list["confc.name"]="DESC";
		
		$str="fa.pos";
		$_SESSION['sortn']=$str;
		$_SESSION['sort']=$list;
	}else{
		$str=$_SESSION['sortn'];
		$list=$_SESSION['sort'];
	}
	
	$insertFavourite = mysql_query("INSERT INTO favourite(monitor_ID,camera_ID,pos) VALUES($monitorid,$idcamera,$idposcamera);",$connection);

$sqlM = "SELECT fa.camera_ID,fa.pos,confc.`name` FROM monitor mn, favourite fa,
		 cardisplay cardis,configcamera confc WHERE mn.Monitor_ID = fa.monitor_ID AND cardis.id = confc.id 
		AND fa.camera_ID = cardis.id AND mn.Monitor_ID = $monitorid ";
$selectMonitor = mysql_query($sqlM." ORDER BY ".$str." ".$list[$str],$connection);
	$_SESSION['sort']=$list;
?>
<div id="divscrollLeft" style="overflow:scroll;overflow-x: hidden; width:100%; height:<?php echo ($winH-360)."px"?>;  background-color: #ffffff">
	 			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebodyleft">
	                 <tbody>
	                	<?php
	                		$i = 0; 
	                		while ($row = mysql_fetch_array($selectMonitor)){ 
	                			$i ++;?>
						<tr onclick="onclickrecordcheck('checkboxcamera<?=$i?>')">
							<td style="width: 8%;text-align: center;">
								<input onclick="onclickrecordcheck('checkboxcamera<?=$i?>')" type="checkbox" name="checkboxcamera[]" id="checkboxcamera<?=$i?>"  value="<?=$row[camera_ID]?>"  class="checkCamera"/></td>
							<td style="width: 8%;text-align: center;"><?=$i?></td>
							<td style="width: 18%;text-align: center;"><?=$row[camera_ID]?></td>
							<td style="width: 46%;"><?=$row[name]?></td>
							<td style="width: 10%;text-align: center;"><?=$row[pos]?></td>
							<td class="last" style="width: 10%;border-right: none !important;text-align: center;"><a  href="#?w=500" onclick="loadEditMonitor_Popup('<?=$i?>','<?=$row[camera_ID]?>','<?=$row[name]?>','<?=$row[pos]?>',this);"
													rel="popup_name2" class="poplight"><?php echo $l_edit?></a></td>
						</tr>
						<?php
						}
						if ($i>0 and $i<($winH/28)) {
							 	foreach(range(0,intval($winH/28)-$i) as $real){
							 		?>
							 		<tr>
							 			<td style="width: 8%;text-align: center;">&nbsp;</td>
									 	<td  style="width: 8%;text-align: center;">&nbsp;</td>
									 	<td style="width: 18%;text-align: center;">&nbsp;</td>
									 	<td  style="width: 46%;text-align: center;">&nbsp;</td>
									 	<td  style="width: 10%;text-align: center;">&nbsp;</td>
									 	<td  class="last" style="width: 10%;border-right: none !important;">&nbsp;</td>
								 	</tr>
							 	<?php }
							}?>
						
						</tbody>
	                </table>
	                </div>
	  <?php mysql_close($connection);?>